package com.deng.mina.common.filter;

import com.deng.mina.common.util.LogUtils;
import org.apache.mina.core.filterchain.IoFilterAdapter;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.core.write.WriteRequest;

/**
 * @Project
 * @Module
 * @JDK_Vserion 1.8
 * @Author DengLibin
 * @Email dlb@smarthse.cn
 * @Desc mina自定过滤器
 * @since 2019/9/17 0017 16:58
 */
public class MyFilter extends IoFilterAdapter {
    /**
     * 接收到数据后时调用
     * @param nextFilter
     * @param session
     * @param message
     * @throws Exception
     */
    @Override
    public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
        LogUtils.info("MyFilter received:"+message.getClass().getName()); // message是一个缓冲区
        super.messageReceived(nextFilter, session, message);
    }

    /**
     * 发送之前调用
     * @param nextFilter
     * @param session
     * @param writeRequest
     * @throws Exception
     */
    @Override
    public void messageSent(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception {
        LogUtils.info("MyFilter sent:");
        super.messageSent(nextFilter, session, writeRequest);
    }
}
